package cn.tworice.admin.web;

import cn.tworice.admin.service.StudentService;
import cn.tworice.common.entity.Companies;
import cn.tworice.common.entity.Student;
import com.lmk.core.web.support.api.RequestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/student")
@CrossOrigin
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("list")
    @ApiOperation("获取学生信息列表")
    public RequestResult list(Integer pageSize, Integer page) {
        RequestResult result = new RequestResult();
        result.appendData("list", studentService.getList(page, pageSize));
        result.appendData("total", studentService.getTotal());
        return result;
    }

    @PostMapping("edit")
    @ApiOperation("编辑或添加学生信息")
    public RequestResult edit(Student student, Integer pageSize, Integer page) {
        RequestResult result = new RequestResult();
        studentService.setStudent(student);
        result.appendData("list", studentService.getList(page, pageSize));
        result.appendData("total", studentService.getTotal());
        return result;
    }

    @DeleteMapping("del")
    @ApiOperation("删除学生信息")
    public RequestResult del(String id, Integer pageSize, Integer page) {
        RequestResult result = new RequestResult();
        studentService.del(id);
        result.appendData("list", studentService.getList(page, pageSize));
        result.appendData("total", studentService.getTotal());
        return result;
    }
}
